// 居中新窗
function ocwindow(url,name,iWidth,iHeight){
	  var url;                                 //转向网页的地址;
	  var name;                           //网页名称，可为空;
	  var iWidth;                          //弹出窗口的宽度;
	  var iHeight;                        //弹出窗口的高度;
	  var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
	  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
	  window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes');
}


//=========================================================================================
// 点击后禁止按钮
//=========================================================================================
// 记录按钮显示名称
var submitButtonOldValue;
// 倒计时秒
var submitButtonCountDownSeconds = 2;
// 计时器句柄
var invervalTimer;

// 禁止按钮可用性
function disableSubmitButton(obj) {
	var sb;
	if ( arguments.length != 0 ) {
		sb = obj;
	} else {
		sb = document.getElementById("submitButton");
	}
	submitButtonOldValue = sb.value;
	sb.disabled = true;
	invervalTimer = setInterval("countdownSubmitButton()", 600);  // 倒计时间隔600毫秒
}

// 按钮禁止倒计时读秒
function countdownSubmitButton() {
	var sb = document.getElementById("submitButton");
	sb.value = "( " + (submitButtonCountDownSeconds--) + " )";
	if ( -2 == submitButtonCountDownSeconds ) {
		clearInterval(invervalTimer);
		sb.disabled = false;
		sb.value = submitButtonOldValue;
		submitButtonCountDownSeconds = 2;
	}
}
function validateNum(obj,headstr){
	var num=obj.value
     num=trim(num);
     var tempnum="";
	if(num.length > 1){
	  tempnum = num.substring(0,num.length - 1);
	}
	var retrunnum = num;
	if(num.substring(num.length-1,num.length)=="H"){
		num = num.substring(0,num.length-1);
	}
	else if(num.substring(num.length-1,num.length)=="P"){
		num = num.substring(0,num.length-1);
	}
	else{
		num = num;
	}
	if(!isNaN(tempnum)){
	     var str_sno="";
		 var aDate=new   Date();   
	     var thisYeat=aDate.getYear();
	     var thisMonth=(aDate.getMonth()+1)+'';
	     if(thisMonth.length==1)thisMonth="0"+thisMonth;
		 if(num.length==13){
		 	str_sno = num;
		 }
		 else if(num.length<=12){
		 if(num.length==1) str_sno=headstr+ thisYeat + thisMonth + "000" + num;
	     if(num.length==2) str_sno=headstr+ thisYeat + thisMonth + "00" + num;
		 if(num.length==3) str_sno=headstr+ thisYeat + thisMonth + "0" + num;
		 if(num.length==4) str_sno=headstr+ thisYeat + thisMonth +  num;
	     if(num.length==5) str_sno=headstr+ thisYeat + "0" +  num;
	     if(num.length==6)
		  {
		    var valNum1 = num.substring(0,2);
			valNum1=parseInt(valNum1);
			 if((num.substring(0,1)=="0"||num.substr(0,1)=="1")&&(valNum1<=12)) str_sno="24"+ thisYeat +  num;
		 	else str_sno="";
		  }
		  if(num.length >6)
		  {  
		    var valNum=num.substring(num.length-5,num.length-6);
	        var valNum2 = num.substring(num.length-4,num.length-6);
			if((valNum=="0"||valNum=="1")&&(valNum2<=12)){ 
			 if(num.length==7)str_sno=headstr+ "200" +  num;
			 if(num.length==8)str_sno=headstr+ "20" +  num;
			 if(num.length==9)str_sno=headstr+ "2" +  num;        
			 if(num.length==10)str_sno=headstr+ num;
			 if(num.length==11)str_sno="2"+ num;
	         if(num.length==12)str_sno= num;
			}
		 	else{ str_sno="";}
		  }
		  if(str_sno != ""){
		  	if(retrunnum.substring(retrunnum.length-1,retrunnum.length)=="H"){
		  		str_sno = str_sno+"H";
		  	}
		  	else{
		  		str_sno = str_sno+"P";
		  	}
		  }	   
	  }else{
	  	str_sno="";
	  }
	}else{
			alert("请输入数字");
			return false;
	}	
	 obj.value=str_sno;
}

function validateNumPri(obj,headstr){
	
	var num=obj.value;
     num=trim(num);
     var tempnum="";
	if(num.length > 1){
	  tempnum = num.substring(0,num.length - 1);
	}
	var retrunnum = num;
	if(num.substring(num.length-1,num.length)=="G"){
		num = num.substring(0,num.length-1);
	}
	else{
		num = num;
	}
	
	if(!isNaN(tempnum)){
	     var str_sno="";
		 var aDate=new   Date();   
	     var thisYeat=aDate.getYear();
	     //var thisMonth=(aDate.getMonth()+1)+'';
	     //if(thisMonth.length==1)thisMonth="0"+thisMonth;
		 if(num.length==12){
		 	str_sno = num;
		 }
		 else if(num.length<=11){
			 if(num.length==1) str_sno=headstr+ thisYeat + "5000" + num;
		     if(num.length==2) str_sno=headstr+ thisYeat + "500" + num;
			 if(num.length==3) str_sno=headstr+ thisYeat + "50" + num;
			 if(num.length==4) str_sno=headstr+ thisYeat + "5" +  num;
		     if(num.length==5) str_sno=headstr+ thisYeat +  num;
			 if(num.length >5)
			  {  
			     if(num.length==6)str_sno=headstr+ thisYeat.substring(0,3) +  num;
				 if(num.length==7)str_sno=headstr+ "20" +  num;
				 if(num.length==8)str_sno=headstr+ "2" +  num;        
				 if(num.length==9)str_sno=headstr+ num;
				 if(num.length==10)str_sno=headstrsubstring(0,1)+ num;
		         if(num.length==11)str_sno= num;
			  }
		  }
		  if(str_sno != ""){
		  	str_sno = str_sno+"G";
		  }
		  else{
	  		str_sno="";
	  		}
	}else{
			alert("请输入数字");
			return false;
	}	
	 obj.value=str_sno;
}

function validateApecSerial(obj,headstr){	
	var num=obj.value
  num=trim(num);
  var tempnum="";
	if(num.length > 1){
	  tempnum = num.substring(0,num.length - 1);
	}
	if(!isNaN(tempnum)){
	     var str_sno="";
		 var aDate=new   Date();   
	     var thisYeat=aDate.getYear();
	     var thisMonth=aDate.getMonth()+1;
		 if(thisMonth.length==1)thisMonth="0"+thisMonth;
		 if(num.length==13){
		 	str_sno = num;
		 }
		 else if(num.length<=12){
		 if(num.length==1) str_sno=headstr+ thisYeat + thisMonth + "000" + num + "A";
	     if(num.length==2) str_sno=headstr+ thisYeat + thisMonth + "00" + num + "A";
		 if(num.length==3) str_sno=headstr+ thisYeat + thisMonth + "0" + num + "A";
		 if(num.length==4) str_sno=headstr+ thisYeat + thisMonth +  num + "A";
	     if(num.length==5) str_sno=headstr+ thisYeat + "0" +  num + "A";
	     if(num.length==6)
		  {
		    var valNum1 = num.substring(0,2);
			valNum1=parseInt(valNum1);
			 if((num.substring(0,1)=="0"||num.substr(0,1)=="1")&&(valNum1<=12)) str_sno="24"+ thisYeat +  num + "A";
		 	else str_sno="";
		  }
		  if(num.length >6)
		  {  
		    var valNum=num.substring(num.length-5,num.length-6);
	        var valNum2 = num.substring(num.length-4,num.length-6);
			if((valNum=="0"||valNum=="1")&&(valNum2<=12)){ 
			 if(num.length==7)str_sno=headstr+ "200" +  num + "A";
			 if(num.length==8)str_sno=headstr+ "20" +  num + "A";
			 if(num.length==9)str_sno=headstr+ "2" +  num + "A";        
			 if(num.length==10)str_sno=headstr+ num + "A";
			 if(num.length==11)str_sno="2"+ num + "A";
	         if(num.length==12)str_sno= num + "A";
			}
		 	else{ str_sno="";}
		  }	   
	  }else{
	  	str_sno="";
	  }
	}else{
			alert("请输入数字");
			return false;
	}	
	 obj.value=str_sno;
}

function validateApecBar(obj,headstr){
	var num=obj.value
  num=trim(num);
	if(!isNaN(num)){
	   var str_sno="";
		 var aDate=new Date();   
	   var thisYeat=aDate.getYear();
		 if(num.length==14){
		 	str_sno = num;
		 }else if(num.length<=7){
			 if(num.length==1) str_sno=headstr+ thisYeat + "3000000" + num;
		   if(num.length==2) str_sno=headstr+ thisYeat + "300000" + num;
			 if(num.length==3) str_sno=headstr+ thisYeat + "30000" + num;
			 if(num.length==4) str_sno=headstr+ thisYeat + "3000" + num;
		   if(num.length==5) str_sno=headstr+ thisYeat + "300" +  num;
		   if(num.length==6) str_sno=headstr+ thisYeat + "30" +  num;
		   if(num.length==6) str_sno=headstr+ thisYeat + "3" +  num;
		   if(num.length==7) str_sno=headstr+ thisYeat + num;
	  }else if(num.length>7 && num.length <14 ){
	  	 alert("输入末位非零开头的数字即可！");
			 return false;
	  }
	  else{
	  	alert("输入的位数不正确！");
			return false;
	  }
	}else{
			alert("请输入数字");
			return false;
	}	
	 obj.value=str_sno;
	 return true;
}

function trim(str)
{
	var left = 0;
	var right = -1;
	for(var i=0;i<str.length;i++)
		if(str.charAt(i)!=" ")
		{
			left = i;
			break;
		}
	for(var i=str.length-1;i>=0;i--)
		if(str.charAt(i)!=" ")
		{
			right = i+1;
			break;
		}
	return str.substring(left,right);
}
/////////////////////////////////////////////////////////////////////////////////////////////